<?php

class Purchases extends Zend_Db_Table_Abstract
{
	private $_name = 'purchases';

	private $_errorCode = 'SUCCEEDED';
	private $_errorStr = "";
	
	public function getErrorCode()
	{
		return $this->_errorCode;
	}
	
	public function getErrorStr()
	{
		return $this->_errorStr;
	}
	
	public function getPurchasesForFDMSCaseNum( $FDMS_case_num )
	{
		if( !isset($FDMS_case_num) )
		{
			$this->_errorCode = "INVALID_PARAMS";
			$this->_errorStr = "Missing FDMS case number";
			return null;
		}
		
		$items = array();
		
		try
		{
			$rows = $this->fetchAll("FDMS_case_num='$FDMS_case_num'");
			foreach($rows as $row)
				$items[] = $row->toArray();
		}
		catch(Exception $e)
		{
			$this->_errorCode = "SQL_EXCEPTION";
			$this->_errorStr = "SQL Exception: ".$e;
			return null;
		}
		
		return $items;
	}
	
	public function setPurchasesForFDMSCaseNum( &$items, $FDMS_case_num )
	{
		if( !isset($FDMS_case_num) )
		{
			$this->_errorCode = "INVALID_PARAMS";
			$this->_errorStr = "Missing FDMS case number";
			return null;
		}
				
		try
		{
			$numrows = $ths->delete("FDMS_case_num='$FDMS_case_num'");
			
			$numrows = 0;
			foreach( $items as $item )
			{
				$numrow = $this->insert( $item );
				$numrows++;
			}
		}
		catch(Exception $e)
		{
			$this->_errorCode = "SQL_EXCEPTION";
			$this->_errorStr = "SQL Exception: ".$e;
			return null;
		}
		
		return $numrows;
	}
}

?>